/**
 * 企信
 */

import qixinSdk from '@/utils/qixin.sdk'
import qixinApi from '@page/api/qixin'

export default {
  namespaced: true,
  state () {
    return {
      userInfo: {}
    }
  },
  getters: {

  },
  mutations: {

  },
  actions: {
    setUserInfo ({ state }) {
      // 通过企信sdk获取企信用户信息
      return qixinSdk.getUserInfo(userInfo => {
        // 保存用户信息
        return qixinApi.saveUserInfo(userInfo).then(response => {
          let { json } = response
          if (json.errcode === '0') {
            userInfo.userId = json.userId
            state.userInfo = userInfo
            console.log(userInfo)
          } else {
            console.log(json.errmsg)
          }
        })
      })
    }
  }
}
